   subroutine ccsdt_calcaab_2(ieaa, iebb, t1aa_i, t1aa_j, t1bb_k, &
                 t2aa_ij, t2ab_ik, t2ab_jk, t2ba_ki, t2ba_kj,&
                 t2aa2_i, t2aa2_j,t2ab2_k, t2ba2_i, t2ba2_j, &
                 iijkaaa_ij, iijkaab_ik, iijkaab_jk,  &
                 iijkaba_ki, iijkaba_kj, &
                 iabijaa_ij, iabijab_jk, iabijab_ik, & 
                 tmpv1, tmpv2, tmpv3, tmpv4, tmpv5, tmpe, &
                 iabciaa_i, iabciaa_j, iabciab_k, &
                 iabciba_i, iabciba_j, &
                  irrepi, irrepj, irrepk, i, j, k,          &
                 ioffvvvoaa, ioffvvvoab, ioffvvvoba,    &
                ioffvvoo2aa, ioffvvoo2ab, ioffvvoo2ba,&
                ioffvoaa, ioffvobb,&
                ioffvoooaa, ioffvoooab,&
                ioffvoooba, ioffvvooaa,&
                ioffvvooab, ioffvvooba,&
                 icore, e4t, e5st, vrta, vrtb, popa, popb, iop)
   use omp_lib
   use mod_symm, only: dirprd
   use mod_orbit, only: noa, zorb
   use mod_iop, only: totgpu
   use mod_t
   implicit none 
!
  integer, intent(in) :: iop, vrta(8), vrtb(8), popa(8), popb(8)
  real*8, intent(inout) :: e4t, e5st
  real*8, intent(in) :: ieaa(*),iebb(*), t1aa_i(*), t1aa_j(*) 
  real*8, intent(in) :: t1bb_k(*), t2aa_ij(*), t2ab_ik(*), t2ab_jk
  real*8, intent(in) :: t2ba_ki(*), t2ba_kj(*)
  real*8, intent(in) :: t2aa2_i(*), t2aa2_j(*), t2ab2_k(*) 
  real*8, intent(in) :: t2ba2_i(*), t2ba2_j(*), icore(*)
  real*8, intent(in) :: iijkaaa_ij(*), iijkaab_ik(*), iijkaab_jk(*)
  real*8, intent(in) :: iijkaba_ki(*), iijkaba_kj(*)
  real*8, intent(in) :: iabijaa_ij(*), iabijab_jk, iabijab_ik(*)
  real*8, intent(in) :: iabciaa_i(*), iabciaa_j(*), iabciab_k(*)
  real*8, intent(in) :: iabciba_i(*), iabciba_j
  real*8, intent(in) :: tmpv1(*), tmpv2(*), tmpv3(*), tmpv4(*), tmpv5(*), tmpe(*)
!
 integer, intent(in) ::  i, j, k, irrepi, irrepj, irrepk
 integer, intent(in) ::  ioffvvvoaa(noa,8), ioffvvvoab(noa, 8), ioffvvvoba(noa, 8)
 integer, intent(in) ::  ioffvvoo2aa(noa, 8), ioffvvoo2ab(noa, 8), ioffvvoo2ba(noa, 8)
 integer, intent(in) ::  ioffvoaa(noa, 8), ioffvobb(noa, 8)
 integer, intent(in) ::  ioffvoooaa(noa,noa,8,8), ioffvoooab(noa, noa, 8, 8)
 integer, intent(in) ::  ioffvoooba(noa,noa, 8, 8), ioffvvooaa(noa,noa,8,8)
 integer, intent(in) ::  ioffvvooab(noa, noa, 8, 8), ioffvvooba(noa, noa, 8, 8)!
 real*8, allocatable :: tmptest(:)
   integer irrepij, irrepjk, irrepki, irrepabc
   integer a,b,c,e,m, idx,idx2
   integer numi, numj, numk, numab
   integer numa, numb, numc, irrepa, irrepb, irrepc
   integer irrepab, irrepbc, irrepca, numbc, numca
   integer ioff1, ioff2, nsize2
   integer idxi, idxj, idxk, idxa, idxb, idxc
   integer nsize, istartij, ioff21, ioff22, ioff23  
   double precision eatmp, vtmp, vtmp2
   double precision tgemmc, tsstgenc, tdoc, tt2, tt1, rt2, rt1
   double precision tgemmr, tsstgenr, tdor
!  
   integer i0, i1, i2, i3 
   integer, external :: irpdso, idsymsoc, isymoffso
   real*8, external :: nrm2so, ddot, dotso, dotso2

   allocate(tmptest(2))
   irrepij = dirprd(irrepi, irrepj)
   irrepjk = dirprd(irrepj, irrepk) 
   irrepki = dirprd(irrepk, irrepi) 
   irrepabc = dirprd(irrepij, irrepk)
   nsize = idsymsoc(irrepabc, vrta, vrta, 1, vrtb, zorb, 1)
   i0 = 1 
   i1 = i0 + nsize
   i2 = i1 + nsize 
   i3 = i2 + nsize
!--tmpv21:bca
!---tmp(a,b,c) = IABCIAB(B,c,E,k)*T2AA(A,E,I,J)
      call cpu_time(tt1); call walltimeso(rt1)
         ioff1 = ioffvvvoab(k, irrepk)  
         ioff2 = ioffvvooaa(i,j,irrepi, irrepj)
         call VpqmnVrsmn_to_Vpqrs(iabciab_k, t2aa_ij,&
             irrepk, irrepij, vrta, zorb, 1, vrta, vrtb, 1, &
             vrta, zorb, 1, tmpv1, irrepabc, 1.d0, 0.d0)
!---tmp(a,b,c) = T2AB(b,c,m,k)*IIJKA<m,a,i,j>}
         ioff1 = ioffvvoo2ab(k,irrepk)
         ioff2 = ioffvoooaa(i,j,irrepi,irrepj)
         call VpqmnVmnrs_to_Vpqrs(t2ab2_k,iijkaaa_ij,&
                irrepk, irrepij, popa, zorb, 1, vrta, vrtb, 1,  &
                vrta, zorb, 1 , tmpv1, irrepabc, 1.d0, 1.d0)
! -------------(312-321)------------ 
!---tmp(a,b,c) = IABCIBA(c,b,e,j)*T2AB(a,e,i,k)-IABCIBA(c,b,e,i)*T2AB(a,e,j,k)}
!--tmpv22:cba
            ioff1 = ioffvvvoba(j,irrepj)
            ioff2 = ioffvvooab(i,k,irrepi,irrepk)
            call VpqmnVrsmn_to_Vpqrs(iabciba_j, t2ab_ik,&
                irrepj, irrepki, vrtb, zorb, 1, vrtb, vrta, 1,&
                vrta, zorb, 1, tmpv2, irrepabc, 1.d0, 0.d0)
            ioff1 = ioffvvvoba(i,irrepi)
            ioff2 = ioffvvooab(j,k,irrepj, irrepk)
            call VpqmnVrsmn_to_Vpqrs(iabciba_i, t2ab_jk,&
                irrepi, irrepjk,  vrtb, zorb, 1, vrtb, vrta, 1,&
                vrta, zorb, 1, tmpv2, irrepabc, -1.d0, 1.d0)
!---tmp(a,b,c) = -T2BA(cBmJ)IIJKABA<mA|kI>+T2BA(cB,mI)*IIJKABA<mA|kJ>
            ioff1 = ioffvvoo2ba(j,irrepj)
            ioff2 = ioffvoooba(k,i,irrepk,irrepi)
            call VpqmnVmnrs_to_Vpqrs(t2ba2_j,iijkaba_ki,&
                irrepj, irrepki, popb, zorb, 1, vrtb, vrta, 1,&
                vrta, zorb, 1 , tmpv2, irrepabc, -1.d0, 1.d0)
            ioff1 = ioffvvoo2ba(i,irrepi)
            ioff2 = ioffvoooba(k,j,irrepk,irrepj)
            call VpqmnVmnrs_to_Vpqrs(t2ba2_i,iijkaba_kj,&
                irrepi, irrepjk, popb, zorb, 1, vrtb, vrta, 1,&
                vrta, zorb, 1 , tmpv2, irrepabc, 1.d0, 1.d0)
! -------------(321-312)------------ 
!---tmp(a,b,c) = IABCIAa(a,b,e,j)*T2BA(c,e,k,i)-IABCIAA(a,b,e,i)*t2BA(c,e,k,j)
!--tmpv23:abc
            ioff1 = ioffvvvoaa(j,irrepj)
            ioff2 = ioffvvooba(k,i,irrepk,irrepi)
            call VpqmnVrsmn_to_Vpqrs(iabciaa_j,t2ba_ki,&
                irrepj, irrepki, vrta, zorb, 1, vrta, vrta, 0,  &
                vrtb, zorb, 1, tmpv3, irrepabc, 1.d0, 0.d0)
            ioff1 = ioffvvvoaa(i,irrepi)
            ioff2 = ioffvvooba(k,j,irrepk,irrepj)
            call VpqmnVrsmn_to_Vpqrs(iabciaa_i, t2ba_kj,&
                irrepi, irrepjk, vrta, zorb, 1, vrta, vrta, 0,   &
                vrtb, zorb, 1, tmpv3, irrepabc, -1.d0, 1.d0)
!---tmp(a,b,c) = Pab_[T2(AB,MI)<Mc|Jk>-T2(AB,MJ)*<Mc|Ik>]
            ioff1 = ioffvvoo2aa(i,irrepi)
            ioff2 = ioffvoooab(j,k,irrepj,irrepk)
            call VpqmnVmnrs_to_Vpqrs(t2aa2_i,iijkaab_jk,&
                irrepi, irrepjk, popa, zorb, 1, vrta, vrta, 0,   &
                vrtb, zorb, 1 , tmpv3, irrepabc, 1.d0, 1.d0)
            ioff1 = ioffvvoo2aa(j,irrepj)
            ioff2 = ioffvoooab(i,k,irrepi,irrepk)
            call VpqmnVmnrs_to_Vpqrs(t2aa2_j,iijkaab_ik,&
                irrepj, irrepki, popa, zorb, 1, vrta, vrta, 0,   &
                vrtb, zorb, 1 , tmpv3, irrepabc, -1.d0, 1.d0)
           if(totgpu==1) then 
           call myicopy_c(tmpv3, tmptest, 1)
           endif
      call cpu_time(tt2); call walltimeso(rt2)
            tvpq = tvpq + rt2-rt1
!---tmpv1:bca  tmpv2:cba  tmpv3:abc
!          nsize = idsymsoc(irrepj, vrta, vrta, 1, vrtb, zorb, 1)
!          write(6,*)'norm of abciba_j', nrm2so(nsize, iabciba_j, 1)
      call cpu_time(tt1); call walltimeso(rt1)
       call symabcaab(tmpv3, tmpv1, tmpv2, tmpv4, vrta, vrtb, irrepabc)
           if(totgpu==1) then 
           call myicopy_c(tmpv3, tmptest, 1)
           endif
      call cpu_time(tt2); call walltimeso(rt2)
            tgen = tgen + rt2-rt1
!         nsize = idsymsoc(irrepabc, vrta,vrta,0, vrtb, zorb, 1)
!          write(6,*)'norm of tmpv4', nrm2so(nsize, tmpv4, 1)
!
!----tmpv3(a,b,c) =
!         t1(a,i)*iabijab(b,c,j,k)
!       - t1(b,i)*iabijab(a,c,j,k)
!       - t1(a,j)*iabijab(b,c,i,k)
!       + t1(b,j)*iabijab(a,c,i,k)
!       + t1(c,k)*iabijaa(a,b,i,j)
! tmpv31:bca
      call cpu_time(tt1); call walltimeso(rt1)
            ioff1 = ioffvvooab(j,k,irrepj,irrepk)
            ioff2 = ioffvoaa(i,irrepi)
            call VpqmnVrsmn_to_Vpqrs(iabijab_jk,t1aa_i,&
               irrepjk, irrepi, zorb, zorb, 1, vrta, vrtb, 1,   &
               vrta, zorb, 1, tmpv1, irrepabc, 1.d0, 0.d0)
            ioff1 = ioffvvooab(i,k,irrepi,irrepk)
            ioff2 = ioffvoaa(j,irrepj)
            call VpqmnVrsmn_to_Vpqrs(iabijab_ik,t1aa_j,&
               irrepki, irrepj, zorb, zorb, 1, vrta, vrtb, 1,   &
               vrta, zorb, 1, tmpv1, irrepabc, -1.d0, 1.d0)
! tmpv32:abc
            ioff1 = ioffvvooaa(i,j,irrepi,irrepj)
            ioff2 = ioffvobb(k,irrepk)
            call VpqmnVrsmn_to_Vpqrs(iabijaa_ij,t1bb_k,&
               irrepij, irrepk, zorb, zorb, 1, vrta, vrta, 1,     &
               vrtb, zorb, 1, tmpv2, irrepabc, 1.d0, 0.d0)
           if(totgpu==1) then 
           call myicopy_c(tmpv3, tmptest, 1)
           endif
      call cpu_time(tt2); call walltimeso(rt2)
            tvpq = tvpq + rt2-rt1
!---tmp(a,b,c) = tmp(a,b,c)+tmp(b,c,a)+tmp(c,a,b)
      call cpu_time(tt1); call walltimeso(rt1)
       call symabcaab2(tmpv2, tmpv1, tmpv5, vrta, vrtb, irrepabc)
           if(totgpu==1) then 
           call myicopy_c(tmpv3, tmptest, 1)
           endif
      call cpu_time(tt2); call walltimeso(rt2)
            tgen = tgen + rt2-rt1
!          nsize = idsymsoc(irrepabc, vrta, vrta, 0, vrtb, zorb, 1)
!          write(6,*)'norm of tmpv5', nrm2so(nsize, tmpv5, 1)
!
!calc Dabc(a,b,c) =V3abc/(ea+eb+ec-ei-ej-ek)
!
      call cpu_time(tt1); call walltimeso(rt1)
!          nsize = idsymsoc(irrepj, vrta, vrta, 1, vrtb, zorb, 1)
!          write(6,*)'norm of abciba_j', nrm2so(nsize, iabciba_j, 1)
      call calceaab(ieaa, ieaa, tmpe, tmpv4, i, j, k, &
                irrepi, irrepj, irrepk, vrta, vrtb, popa, popb)
!          nsize = idsymsoc(irrepabc, vrta, vrta, 0, vrtb, zorb, 1)
!          write(6,*)'norm of tmpve', nrm2so(nsize, tmpe, 1)
!          nsize = idsymsoc(irrepj, vrta, vrta, 1, vrtb, zorb, 1)
!          write(6,*)'norm of abciba_j', nrm2so(nsize, iabciba_j, 1)
      nsize = idsymsoc(irrepabc, vrta, vrta, 0, vrtb, zorb, 1)
      e4t  = e4t + dotso(nsize, tmpe, 1, tmpv4, 1)
      e5st = e5st + dotso(nsize, tmpe, 1, tmpv5, 1)
           if(totgpu==1) then 
           call myicopy_c(tmpv3, tmptest, 1)
           endif
      call cpu_time(tt2); call walltimeso(rt2)
            ttmpe = ttmpe + rt2-rt1
      call cpu_time(tt1); call walltimeso(rt1)
      e4ttest  = e4ttest + dotso2(nsize, tmpe, 1, tmpv4, 1)
      e5sttest = e5sttest + dotso2(nsize, tmpe, 1, tmpv5, 1)
      call cpu_time(tt2); call walltimeso(rt2)
            ttmpe2 = ttmpe2 + rt2-rt1
      return
      end











      
